package com.zrf.springCloudTest.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 消费服务
 * @author zrf
 *         Created by zrf on 2016/8/30.
 */
@Service
public class ComputeService {

    /**
     * restTemplate
     */
    @Resource
    private RestTemplate restTemplate;

    /**
     * 添加方法
     * @param a 参数a
     * @param b 参数b
     * @return a+b
     */
    @HystrixCommand(fallbackMethod = "addFallBack")
    public String add(Integer a, Integer b){
        return restTemplate.getForEntity("http://COMPUTE-SERVICE/add?a="+ a +"&b=" + b, String.class).getBody();
    }

    /**
     * 失败毁掉方法
     * @return 错误信息
     */
    public String addFallBack(){
        return "error";
    }

    /**
     * 失败回调方法
     * @param a 参数a
     * @param b 参数b
     * @return 异常信息
     */
    public String addFallBack(Integer a, Integer b){
        return "error1";
    }
}
